<?php
if ( function_exists('register_sidebar') )
    register_sidebar(array('name'=>'1',
        'before_widget' => '<div class="bottom-box">',
        'after_widget' => '</div>',
        'before_title' => '<div class="header">',
        'after_title' => '</div>',
    ));
    register_sidebar(array('name'=>'2',
        'before_widget' => '<div class="bottom-box">',
        'after_widget' => '</div>',
        'before_title' => '<div class="header">',
        'after_title' => '</div>',
    ));
    register_sidebar(array('name'=>'3',
        'before_widget' => '<div class="bottom-box">',
        'after_widget' => '</div>',
        'before_title' => '<div>',
        'after_title' => '</div>',
    ));

function add_nofollow($matches) {
	$origin = get_bloginfo('wpurl');
	if ((strpos($matches[2],$origin)) === false && ( strpos($matches[1],'rel="nofollow"') === false ) && ( strpos($matches[3],'rel="nofollow"') === false ) ) {
//	if (strpos($matches[2],$origin) === false) {
		$nofollow = ' rel="nofollow" ';
	} else {
		$nofollow = '';
	}
	return '<a href="' . $matches[2] . '"' . $nofollow . $matches[1] . $matches[3] . '>' . $matches[4] . '</a>';
}

function nofollow_index($output) {
	// Loop through the content of each post and add a nofollow when it's on the main page or a category page.
	if (is_home()) {
		$anchorPattern = '/<a (.*?)href="(.*?)"(.*?)>(.*?)<\/a>/i';
		$output = preg_replace_callback($anchorPattern,'add_nofollow',$output);
	}
	return $output;
}

function add_trailingslash($url, $type) {
	// trailing slashes for everything except is_single()
	// Thanks to Mark Jaquith for this
	if ( 'single' === $type ) {
		return $url;
	} else {
		return trailingslashit($url);
	}
}

function utf8_trim($str) {

	$len = strlen($str);

	for ($i=strlen($str)-1; $i>=0; $i-=1){
		$hex .= ' '.ord($str[$i]);
		$ch = ord($str[$i]);
        if (($ch & 128)==0) return(substr($str,0,$i));
		if (($ch & 192)==192) return(substr($str,0,$i));
	}
	return($str.$hex);
}

//header rsd wlwmanifest�Ƴ�
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');

if (function_exists('wp_generator')) {
	remove_action('wp_head', 'wp_generator');
}

function af_titledespacer($title) {
	return trim($title);
}

function no_self_ping( &$links ) {
	$home = get_option( 'home' );
	foreach ( $links as $l => $link )
		if ( 0 === strpos( $link, $home ) )
			unset($links[$l]);
}
function delete_comment_link($id) {
  if (current_user_can('edit_post')) {
    echo ' | <a href="'.admin_url("comment.php?action=cdc&c=$id").'">del</a> ';
    echo '| <a href="'.admin_url("comment.php?action=cdc&dt=spam&c=$id").'">spam</a>';
  }
}

include_once (TEMPLATEPATH . '/user-functions.php');
add_action( 'pre_ping', 'no_self_ping' );
add_filter('wp_title', 'af_titledespacer');
add_filter('the_content','nofollow_index');
add_filter('user_trailingslashit', 'add_trailingslash', 10, 2);
?>